<template>
    <!--    <div v-html="result.content">-->
    <!--    </div>-->
    <div style="background-color: white;min-height: 800px;">
        <div slot="header" class="clearfix" style="text-align: center;">
            <div style="font-size: 25px;font-weight: bold;color: #00d1b2;">{{result.title}}</div>
        </div>
        <div style="margin-top:10px;color: #a4da89;font-weight: bold;text-align: center">{{result.created}}</div>
        <el-divider></el-divider>
        <div class="text item" style="padding-left: 50px;padding-right: 50px;padding-top: 15px" v-html="result.content">
        </div>
        <br><br><br>
        <div style="text-align: center">
            <el-button type="success" icon="el-icon-message" circle @click="piZhun" v-if="pi">批准请假</el-button>
            <el-button type="danger" icon="el-icon-delete" circle @click="deleted"></el-button>
        </div>
    </div>
</template>

<script>
    import service from "../../utils/request";

    export default {
        name: 'Article',
        data() {
            return {
                pi: false,
                result: {}
            }
        },
        methods: {
            piZhun() {
                service.get('/users/piZhun', {
                    params: {
                        id: this.$route.params.id
                    }
                }).then(res => {
                    this.$message.success('批准成功')
                }).catch(err => {
                    this.$message.error('请检查网络连接')
                })
            },
            deleted() {
                service.get('/users/check', {
                    params: {
                        userId: JSON.parse(localStorage.getItem("userInfo")).id
                    }
                }).then(res => {
                    if (res === 110) {
                        this.$message.error('对不起，您没有权限')
                    } else {
                        let id = this.$route.params.id
                        service.get('/article/delete', {
                            params: {
                                id: id
                            }
                        }).then(res => {
                            this.$message.success('刪除成功')
                            this.$router.push('/')
                        }).catch(err => {
                            this.$message.error('刪除失败，请检查网络连接')
                        })
                    }
                })
            },
            getArticle() {
                let id = this.$route.params.id
                service.get('/article/getArticleById', {
                    params: {
                        id: id
                    }
                }).then(res => {
                    this.result = res
                })
            }, isPi() {
                let rid = JSON.parse(localStorage.getItem('userInfo')).rid;
                if (rid == 3) {
                    this.pi = true
                }
            }
        },
        created() {
            this.isPi()
            this.getArticle()
        }
    }
</script>

<style>
</style>
